#!/bin/bash

WORK_DIR=$(pwd)
TRD_PATH="${WORK_DIR}/binance_trading_summary.csv"
MCH_PATH="${WORK_DIR}/binance_trading_machine.json"
TMP_PATH="${WORK_DIR}/binance_trading_machine.txt"

cd ../coin_deploy && git pull
binance_hosts=$(awk -F, '{print $3}' ${TRD_PATH} | grep -v machine | sort | uniq)
for i in $binance_hosts; do grep -A1 "Host $i" jaewon_strategy/ssh_config/ssh_config | awk '{print $2}' | xargs; done | tee ${TMP_PATH}
cd $WORK_DIR

echo '{' > ${MCH_PATH} && cat ${TMP_PATH} |sed '/^[[:space:]]*$/d'|awk '{ print "  \"" $1 "\": \"" $2 "\","}' >> ${MCH_PATH} && echo '  "EMPTY": "EMPTY"' >> ${MCH_PATH} && echo '}' >> ${MCH_PATH}


CSV_PATH="${WORK_DIR}/binance_trading_ip_list.csv"
TXT_PATH="${WORK_DIR}/binance_trading_ip_list.txt"

VAULT_TOKEN=s.7ko1MmQzb455qHes6uvuiiWH ./pyrunner cc/experimental/wliang/utils/prepare_bind_ip.py  \
    --mount_point=coin_key_high  \
    --vault_addr=https://laksa.joomo.io:8200 \
    --machine_ip_map_path=${MCH_PATH} \
    --account_infos_path=${TRD_PATH} \
    --output_csv_path=${CSV_PATH} \
    --output_txt_path=${TXT_PATH}
